#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

int getIndex(int k)
{
	int ans= 1;
	while (k > 0) {ans *=k; k--;}
	return ans;
}

class Solution {
public:
    string getPermutation(int n, int k) {
        vector<int> table(n, 0);
		for (int i = 0; i < n; i++) table[i] = i+1;
		string ans;
		int size = n;
		
		while(ans.size() < size-1) {
			int index = getIndex(n-1);
			int tmp = (k-1)/index;
			k -= tmp * index;
			ans += '0' + table[tmp];
			table.erase(table.begin()+tmp);
			n--;
		}		
		ans += '0'+ table[0];
		return ans;
        
    }
};


int main(int argc, char **argv)
{
    Solution mySolution;

    cout << "-----------------Test 1--------------------" << endl;
    mySolution.getPermutation(3,4);


    cout << "-----------------Test 2--------------------" << endl;


    cout << "-----------------Test 3--------------------" << endl;


    cout << "-----------------Test 4--------------------" << endl;


    cout << "-----------------Test 5--------------------" << endl;



}
